Method and apparatus for learning low-precision neural network that combines weight quantization and activation quantization

ABSTRACT

A method is provided. The method includes selecting a neural network model, wherein the neural network model includes a plurality of layers, and wherein each of the plurality of layers includes weights and activations; modifying the neural network model by inserting a plurality of quantization layers within the neural network model; associating a cost function with the modified neural network model, wherein the cost function includes a first coefficient corresponding to a first regularization term, and wherein an initial value of the first coefficient is pre-defined; and training the modified neural network model to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, further including optimizing a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, and wherein the quantized weights are quantized using the optimized weight scaling factor.

PRIORITY

This application claims priority under 35 U.S.C. § 119(e) to U.S. Provisional Patent Applications filed on Nov. 7, 2017 and Nov. 8, 2017 in the U.S. Patent and Trademark Office and assigned Ser. Nos. 62/582,848 and 62/583,390, respectively, the entire contents of each of which are incorporated herein by reference.

FIELD

The present disclosure relates generally to neural networks, and more particularly, to a method and apparatus for learning low-precision neural networks that combines weight quantization and activation quantization.

BACKGROUND

Deep neural networks have recently achieved major performance breakthroughs in many computer vision tasks, e.g., image classification, object detection, semantic segmentation, and super resolution. The performance of state-of-the-art neural networks is due to very deep and over-parameterized multi-layer architectures. Currently, millions or tens of millions of parameters in more than one hundred layers are typical. However, the increasing number of network parameters in a large number of layers requires high-performance vector computing processors such as a graphics processing unit (GPU) equipped with a large amount of memory. Moreover, the need for computing power and memory resources grows quickly, as high-resolution images and videos of increasing sizes are processed.

Low-precision implementation of deep neural networks is of great interest recently, particularly for deployment of deep neural networks on resource-limited devices, e.g., battery-powered mobile or portable devices. In such platforms, memory and power are limited. Furthermore, basic floating-point arithmetic operations may not be supported. Low-precision weights (e.g., parameters) and activations (e.g., feature maps) reduce computational costs and lower memory requirements. Hence, low-precision weights and activations are preferred and sometimes necessary for efficient processing with reduced power consumption when computation and power budgets are limited. Memory burden may be curtailed as well using low-precision weights and activations of smaller bit widths instead of full-precision values of larger bit widths.

SUMMARY

According to one embodiment, a method includes selecting a neural network model, wherein the neural network model includes a plurality of layers, and wherein each of the plurality of layers includes weights and activations; modifying the neural network model by inserting a plurality of quantization layers within the neural network model; associating a cost function with the modified neural network model, wherein the cost function includes a first coefficient corresponding to a first regularization term, and wherein an initial value of the first coefficient is pre-defined; and training the modified neural network model to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, further including optimizing a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, and wherein the quantized weights are quantized using the optimized weight scaling factor.

According to one embodiment, an apparatus includes a selector configured to select a neural network model, wherein the neural network model includes a plurality of layers, and wherein each of the plurality of layers includes weights and activations; an insertion device configured to modify the neural network model by inserting a plurality of quantization layers within the neural network model; an association device configured to associate a cost function with the modified neural network model, wherein the cost function includes a first coefficient corresponding to a first regularization term, and wherein an initial value of the first coefficient is pre-defined; and a training device configured to train the modified neural network model to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, and optimize a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, wherein the quantized weights are quantized using the optimized weight scaling factor.

BRIEF DESCRIPTION OF THE DRAWINGS

The above and other aspects, features, and advantages of certain embodiments of the present disclosure will be more apparent from the following detailed description, taken in conjunction with the accompanying drawings, in which:

FIG. 1 illustrates an exemplary flow diagram of a method of a low-precision convolutional layer for a general non-linear activation function that combines weight quantization and activation quantization, according to an embodiment of the present disclosure;

FIG. 2 illustrates an exemplary flow diagram of a method of a low-precision convolutional layer for an ReLU activation function that combines weight quantization and activation quantization, according to an embodiment of the present disclosure;

FIG. 3 illustrates an exemplary a flowchart of a method of quantizing weights and quantizing an activation for a low-precision neural network, according to an embodiment of the present disclosure; and

FIG. 4 illustrates an exemplary flowchart of a method of training a low-precision neural network that combines weight quantization and activation quantization, according to an embodiment of the present disclosure.

DETAILED DESCRIPTION OF EMBODIMENTS OF THE PRESENT DISCLOSURE

Hereinafter, embodiments of the present disclosure are described in detail with reference to the accompanying drawings. It should be noted that the same elements will be designated by the same reference numerals although they are shown in different drawings. In the following description, specific details such as detailed configurations and components are merely provided to assist with the overall understanding of the embodiments of the present disclosure. Therefore, it should be apparent to those skilled in the art that various changes and modifications of the embodiments described herein may be made without departing from the scope of the present disclosure. In addition, descriptions of well-known functions and constructions are omitted for clarity and conciseness. The terms described below are terms defined in consideration of the functions in the present disclosure, and may be different according to users, intentions of the users, or customs. Therefore, the definitions of the terms should be determined based on the contents throughout this specification.

The present disclosure may have various modifications and various embodiments, among which embodiments are described below in detail with reference to the accompanying drawings. However, it should be understood that the present disclosure is not limited to the embodiments, but includes all modifications, equivalents, and alternatives within the scope of the present disclosure.

Although the terms including an ordinal number such as first, second, etc. may be used for describing various elements, the structural elements are not restricted by the terms. The terms are only used to distinguish one element from another element. For example, without departing from the scope of the present disclosure, a first structural element may be referred to as a second structural element. Similarly, the second structural element may also be referred to as the first structural element. As used herein, the term “and/or” includes any and all combinations of one or more associated items.

The terms used herein are merely used to describe various embodiments of the present disclosure but are not intended to limit the present disclosure. Singular forms are intended to include plural forms unless the context clearly indicates otherwise. In the present disclosure, it should be understood that the terms “include” or “have” indicate existence of a feature, a number, a step, an operation, a structural element, parts, or a combination thereof, and do not exclude the existence or probability of the addition of one or more other features, numerals, steps, operations, structural elements, parts, or combinations thereof.

Unless defined differently, all terms used herein have the same meanings as those understood by a person skilled in the art to which the present disclosure belongs. Terms such as those defined in a generally used dictionary are to be interpreted to have the same meanings as the contextual meanings in the relevant field of art, and are not to be interpreted to have ideal or excessively formal meanings unless clearly defined in the present disclosure.

According to one embodiment, the present system and method obtains low-precision neural networks having quantized weights and quantized activations (e.g., feature maps). Quantized weights and quantized activations are represented by fixed-point numbers of low-precision (e.g., lower bit width). Common scaling factors are defined in each layer of a neural network for weights and activations, respectively, to cover their dynamic ranges that vary every layer. The present system and method provides weight quantization and activation quantization.

For weight quantization, the present system trains neural networks with a regularization coefficient of a mean square quantization error (MSQE) for weights in each layer of a neural network. According to one embodiment, a regularization coefficient is a learnable parameter. Initially, the regularization coefficient may be set to be small and a high-precision (e.g., greater bit width) model is trained. As training continues, the present system increases the regularization coefficient gradually such that the regularization coefficient forces weights to be increasingly quantized. The present system completes network training when the regularization coefficient becomes sufficiently large such that the trained model, which began as a high-precision model, converges to a low-precision model having only quantized weights. During training, a scaling factor for weights in each layer is learnable as well such that the present system optimizes the scaling factor to minimize the MSQE.

For activation (e.g., feature map) quantization, the present system includes quantization layers. A quantization layer is a non-linear layer that outputs quantized values of an input. Similar to weight quantization, a learnable scaling factor for activations is defined in each layer and optimized during training. The MSQE for activations in each layer is minimized for optimization. Quantization layers generate quantized activations during training and weights are optimized based on quantized activations. In contrast, weights are not quantized during training iterations, but each weight gradually converges to a quantized value as training proceeds because of the MSQE regularization with an increasing regularization coefficient.

By combining weight quantization and activation quantization processes, the present system provides a unified training method for learning low-precision neural networks. The present system and method further provides regularizing power-of-two scaling factors for weights and activations that may be applied in addition to the present training process for low-precision neural networks, according to one embodiment. A power-of-two scaling may be computationally advantageous when it is implemented by bit-shift rather than scalar multiplication.

According to one embodiment, the present system concerns a low-precision neural network having quantized weights and quantized activations (e.g., feature maps). Quantized weights and quantized activations in each layer are represented by low-precision fixed-point numbers of similar bit widths, respectively. Common scaling factors for weights and activations are additionally defined in each layer of a neural network, respectively, in order to cover their dynamic ranges that vary every layer. The scaling factor is the quantization cell size, which is fixed for linear quantization.

Low-precision neural networks may be implemented by low-precision fixed-point arithmetic operations.

FIG. 1 illustrates an exemplary flow diagram of a method of a low-precision convolutional layer 100 for a general non-linear activation function that combines weight quantization and activation quantization, according to an embodiment of the present disclosure.

Referring to FIG. 1, a fixed-point design of the low-precision convolutional layer 100 includes a convolution operation 101, a bias addition operation 103, a first scale-factor multiplication operation 105, a non-linear activation operation 107, a second scale-factor multiplication operation 109, a quantization operation 111, and an operation 113 for cost function selection, neural network training, quantization cell size optimization, and weight optimization.

The method of FIG. 1 includes selecting a neural network model, wherein the neural network model includes a plurality of layers. In an embodiment, a selector may be used to select the neural network model. Each of the plurality of layers may include weights and activations. The neural network model may be modified by inserting a plurality of quantization layers within the neural network model. In an embodiment, an insertion device may be used to insert the plurality of quantization layers. A cost function is associated with the modified neural network model, where the cost function includes a first coefficient corresponding to a first regularization term, and an initial value of the first coefficient is pre-defined. In an embodiment, an association device may be used to associate the cost function with the modified neural network model. The modified neural network model is trained to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, and optimizing a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, wherein the quantized weights are quantized using the optimized weight scaling factor. In an embodiment, a training device may be used to provide the training.

The weight scaling factor and the activation scaling factor may be optimized based on minimizing a minimum square quantization error (MSQE).

Each quantization layer of the plurality of quantization layers may be inserted after each activation output in each layer within the neural network model.

The cost function may include a second coefficient corresponding to a second regularization term based on the weight scaling factor and the activation scaling factor being power-of-two numbers.

The quantized weights, the weight scaling factor, and the activation scaling factor may be applied to a fixed-point neural network, where the fixed-point neural network includes a plurality of convolutional layers, where each of the plurality of convolutional layers includes a convolution operation configured to receive feature maps and the quantized weights. A bias addition operation may be configured to receive an output of the convolution operation and biases. A first multiplying operation may be configured to receive an output of the bias addition operation and the first scale factor. An activation operation may be configured to receive an output of the first multiplier operation. A second multiplying operation may be configured to receive an output of the activation operation and the second scale factor, and a quantization operation may be configured to receive an output of the second multiplying operation.

The neural network may be trained by updating the weights by a stochastic gradient descent method; updating the weight scaling factor by the stochastic gradient descent method; updating the activation scaling factor by the stochastic gradient descent method; if the weight scaling factor and the activation scaling factor are of a power of two, including additional gradients of the stochastic descent method; updating the regularization coefficients by the stochastic gradient descent method; and terminating the training if either the regularization coefficient is greater than a pre-determined constant or a number of iterations of the method is greater than a predetermined limit.

The weights may be fixed-point weights. The first scale factor may be a product of the weight scaling factor and the activation scaling factor. The activation operation may be a non-linear activation function.

The quantized weights, the weight scaling factor, and the activation scaling factor may be applied to a fixed-point neural network, where the fixed-point neural network includes a plurality of convolutional layers, and where each of the plurality of convolutional layers includes a convolution operation configured to receive feature maps and the quantized weights. A bias addition operation may be configured to receive an output of the convolution operation and biases. A rectified linear unit (ReLU) activation operation may be configured to receive an output of the bias addition operation. A scale-factor multiplying operation may be configured to receive an output of the ReLU activation operation and a scale factor, and a quantization operation may be configured to receive an output of the scale-factor multiplying operation.

The scale factor may be a product of the weight scale factor and the quantization scale factor.

The convolution operation 101 receives a feature map (e.g., a fixed-point (FXP) input) and fixed-point weights (e.g., FXP weights). In one embodiment, the convolution operation 101 is implemented with low-precision fixed-point multipliers and accumulators.

The output of the convolution operation 101 and biases are received and summed by the bias addition operation 103.

The fixed-point weights and input feature maps may be scaled by a weight scaling factor δ_(l) and an input feature map scaling factor Δ_(l-1) for layer l. For example, the output of the bias addition operation 103 may be scaled by a product of the weight scaling factor δ_(l) and the input feature map scaling factor Δ_(l-1) (e.g., Δ_(l-1)δ_(l)) by the first scale-factor multiplication operation 105 receiving the output of the bias addition operation 103 and the scaling factor Δ_(l-1)δ_(l), and generating a product from the same. In one embodiment, scaling of the output of the bias addition operation 103 may be avoided by scaling the biases by the scaling factor Δ_(l-1)δ_(l).

The output of the first scale-factor multiplication operation 105 is received by the first non-linear activation operation 107.

The output of the non-linear activation operation 107 is scaled by a scaling factor scaling factor ¼ For example, the second scale-factor multiplication operation 109 receives the output of the activation operation 107 and a scaling factor (e.g., 1/Δ_(l)) and generates a product of the same.

The output of the second scale-factor multiplication operation 109 is quantized by the quantization operation 111 (e.g., FXP output).

The operation 113 selects a cost function, trains the neural network, optimizes quantization cell size, and optimizes weights.

FIG. 2 illustrates an exemplary flow diagram of a method of a low-precision convolutional layer 200 for an ReLU activation function that combines weight quantization and activation quantization, according to an embodiment of the present disclosure.

Referring to FIG. 2, the low-precision convolutional layer 200 includes a convolution operation 201, a bias addition operation 203, an ReLU operation 205, a scale-factor multiplication operation 207, a quantization operation 209, and an operation 211 for cost function selection, neural network training, quantization cell size optimization, and weight optimization.

The convolution operation 201 receives a feature map (e.g., FXP input) and fixed-point weights (e.g., FXP weights). In one embodiment, the convolution operation 201 is implemented with low-precision fixed-point multipliers and accumulators.

The output of the convolution operation 201 and biases are received and summed by the bias addition operation 203.

The output of the bias addition operation 203 is received by the ReLU operation 205.

The fixed-point weights and input feature maps may be scaled by scaling factors δ_(l) and Δ_(l-1), respectively, for layer l. For example, the output of the ReLU operation 205 may be scaled by a product of the weight scaling factor δ_(l) and the input feature map scaling factor Δ_(l-1) divided by Δ_(l) (e.g., (Δ_(l-1)δ_(l))/Δ_(l)) by the scale-factor multiplication operation 207 receiving the output of the ReLU operation 205 and the scaling factor Δ_(l-1)δ_(l))/Δ_(l), and generating a product from the same. That is, the two scaling operations shown in FIG. 1 are combined into one in FIG. 2. If the scaling factors are power-of-two numbers, then scaling may be implemented by bit shift. Similarly, fully-connected layers may be implemented by replacing convolution with simple matrix multiplication.

The output of the scale-factor multiplication operation 207 is quantized by the quantization operation 209 (e.g., FXP input).

The operation 211 selects a cost function, trains the neural network, optimizes quantization cell size, and optimizes weights.

In a low-precision neural network, bit widths for weights and activations may be provided and fixed. Scaling factors for fixed-point weights and activations may be selected. While determining optimum scaling factors, the present system optimizes low-precision fixed-point weights. According to one embodiment, the present system and method learns the quantization parameters and quantized fixed-point weights simultaneously.

According to one embodiment, the present system and method provides low-precision neural network quantization including weight quantization and activation quantization.

A quantization function may be defined. The number of bits used to represent each quantized value may be provided. For a bit width n, where n is an integer, the quantization function output is as in Equation (1) as follows:

Q _(n)(x;δ)=δ·clip(round(2/δ),[−2^(n−1), 2^(n−1)−1]),   (1)

where x is an input and δ is a quantization cell size (e.g., a common scaling factor); and the rounding and clipping functions are as in Equations (2) and (3) as follows:

round(x)=sign(x)└|x|+0.5┘  (2)

clip(x,[a,b])=min(max(x,a),b)  (3)

where x, a, and b are inputs.

For a general non-linear neural network having L layers, W₁, W₂, . . . , W_(L) are sets of weights in layers 1 to L, respectively, where L is an integer. For notational simplicity, Equation (4) is as follows:

A₁ ^(L) =A ₁ , A ₂ , . . . , A _(L, . . .)   (4)

for any symbol A. For weight quantization, the present system provides a regularization term of the average of the MSQEs for weights in all L layers, i.e., as in Equation (5) as follows:

$\begin{matrix} {{{R_{n}\left( {W_{1}^{L};\delta_{1}^{L}} \right)} = {\frac{1}{N}{\sum\limits_{l = 1}^{L}{\sum\limits_{w \in W_{l}}{{w - {Q_{n}\left( {w;\delta_{l}} \right)}}}^{2}}}}},} & (5) \end{matrix}$

where n is the bit width for low-precision weights, δ_(l) is the quantization cell size, i.e., the common scaling factor, for weights in layer l, and N is the total number of weights in all L layers, i.e., N=Σ_(l=1) ^(L)|W₁ ^(L)|.

According to one embodiment, the present system provides a learnable regularization coefficient to obtain quantized weights gradually using the above MSQE regularization. The regularization coefficient may be another learnable parameter. Starting from a small regularization coefficient (e.g., a pre-defined regularization coefficient), the present system learns a high-precision model with little performance loss. As training continues, the present system increases the regularization coefficient until there are quantized weights at the completion of training. An additional penalty term for a small regularization coefficient is included, e.g.,—log α, where α is the regularization coefficient. The cost function for weight quantization is as in Equation (6) as follows:

C(X, W ₁ ^(L), δ₁ ^(L), α)=L(X; W ₁ ^(L))+αR _(n)(W ₁ ^(L); δ₁ ^(L))−λ log α  (6)

where L(X; W₁ ^(L)) is the original network loss function for training dataset X, and where A is a hyper-parameter that is selected and fixed for training.

The present system optimizes the cost function in network training and updates weights, quantization cell sizes, and the learnable regularization coefficient. Because of the penalty term on a small value of α, i.e.,—log α, where α causes the importance of the regularization term R_(n) to increase continuously during training, which causes the regularization for weight quantization to increase, and causes the weights to be quantized by the completion of training. The regularization coefficient increases gradually so long as the network loss function does not significantly degrade.

For activation quantization, the present system provides quantization layers. For an original full-precision model, quantization layers for activations are inserted wherever needed to quantize activations for a low-precision model, e.g., after every activation function. The present system may insert quantization layers after every existing layer from 1 to L. For an activation x from layer l, the quantization layer outputs Q_(m)(x; Δ_(l)), where Q_(m) is the quantization function for bit width m and Δ_(l) is the learnable quantization cell size (e.g., common scaling factor) for output activations of layer l.

The present system optimizes Δ_(l) by minimizing MSQE for the output activations of layer l as in Equation (7) as follows:

$\begin{matrix} {{{S_{m}\left( {X_{l};\Delta_{l}} \right)} = {\frac{1}{X_{l}}{\sum\limits_{x \in X_{l}}{{x - {Q_{m}\left( {x;\Delta_{l}} \right)}}}^{2}}}},} & (7) \end{matrix}$

where X_(l) is the set of output activation values of layer l for 1≤l≤L. Moreover, l may include l=0 by assuming that a quantization layer is inserted immediately before the first layer to quantize the network input, i.e., where X₀ is the set of network input values and Δ₀ is the quantization cell size for the network input.

Quantization layers are activated in training to generate quantized activations so that weights are optimized for quantized activations. In contrast, the weight quantization method does not actually quantize weights all at once during training. Weights are quantized gradually during training, where each weight gradually converges to a quantized value as training proceeds due to the MSQE regularization with increasing regularization coefficient.

Power-of-two quantization cell sizes (e.g., common scaling factors) provide benefit in computation when implemented by bit shift rather than scalar multiplication. An additional regularization term may be introduced as in Equation (8) follows:

$\begin{matrix} {{{T\left( \delta_{1}^{L} \right)} = {\frac{1}{L}{\sum\limits_{l = 1}^{L}\; {{\delta_{l} - {{round}_{{pow}\; 2}\left( \delta_{l} \right)}}}^{2}}}},} & (8) \end{matrix}$

where round_(pow2) is a rounding function that rounds to the closest power-of-two value, i.e., as in Equation (9) as follows:

$\begin{matrix} {{{round}_{{pow}\; 2}(x)} = {2^{\lfloor{\log_{2}{x}}\rfloor} \cdot {{round}\left( \frac{x}{2^{\lfloor{\log_{2}{x}}\rfloor}} \right)}}} & (9) \end{matrix}$

Using a learnable regularization coefficient, the present system converges the quantization cell sizes gradually to optimal power-of-two values during training. For example, weight quantization with power-of-two quantization cell sizes may be obtained by optimizing the cost function of Equation (10) as follows:

C _(pow2)(X, W ₁ ^(L), δ₁ ^(L), α, β)=L(X; W ₁ ^(L))+αR_(n)(W ₁ ^(L); δ₁ ^(L))−λ log α+βT(δ₁ ^(L))−ζ log β  (10)

where λ and ζ are hyper-parameters that are selected and fixed for training. Similarly, activation quantization cell sizes can be regularized to power-of-two numbers by

${T\left( \Delta_{0}^{L} \right)} = {\frac{1}{L + 1}{\sum\limits_{l = 0}^{L}\; {{{\Delta_{l} - {{round}_{{pow}\; 2}\left( \Delta_{l} \right)}}}^{2}.}}}$

FIG. 3 illustrates an exemplary flowchart of a method of quantizing weights and quantizing an activation for a low-precision neural network, according to an embodiment of the present disclosure.

Referring to FIG. 3, at 301, the present system selects a neural network model with bit widths n and m, where n and m are integers. A quantization method for low-precision neural networks includes selecting an original neural network model, with bit widths n and m for low-precision weights and activations, respectively (e.g., the bit widths may be different for different layers or fixed for all layers).

At 303, the present system modifies the selected neural network model by inserting quantization layers. For example, a quantization layer is inserted after every activation output and before the first layer input.

At 305, the present system selects a cost function. For example, a cost function is as in Equation (11) as follows:

C(X, W ₁ ^(L), δ₁ ^(L), Δ₀ ^(L), α)=L(X; W ₁ ^(L))+αR _(n)(W ₁ ^(L); δ₁ ^(L))−λ log α+ηΣ_(l=0) ^(L) S _(m)(X _(l); Δ_(l))  (11)

where λ and η are hyper parameters selected and fixed prior to training.

At 307, the present system includes additional regularization terms in the cost function if quantization cell sizes are a power of two, as in Equation (12) as follows:

C _(pow2)(X, W ₁ ^(L), δ₁ ^(L), Δ₀ ^(L), α, β₁ ²)=C(X, W ₁ ^(L), δ₁ ^(L), Δ₀ ^(L), α)+β₁ T(δ₁ ^(L))+β₂ T(Δ₀ ^(L))−ζ₁ log β₁−ζ₂logβ₂,   (12)

where and ζ₁ and ζ₂ are hyper parameters selected and fixed prior to training.

At 309, the present system trains the network to generate an optimized quantization sell size.

At 311, the present system optimizes the weights with the optimized quantization cell sizes. After training is terminated, the present system may quantize trained weights with the optimized quantization cell sizes δ₁ ^(L), since the trained weights at the termination of training are quantized but still in high-precision. The loss from 311 may be negligible as long as the weight quantization is successful and a becomes sufficiently large.

FIG. 4 illustrates an exemplary flowchart of a method of training a low-precision neural network that combines weight quantization and activation quantization, according to an embodiment of the present disclosure. According to one embodiment, FIG. 4 may be an implemented as represented by 309 of FIG. 3.

Using stochastic gradient descent with mini-batches, every learnable parameter p (e.g., weights, quantization cell sizes, regularization coefficients) is updated by one of stochastic gradient descent methods, e.g., as in Equation (13) as follows:

$\begin{matrix} {{{p\lbrack t\rbrack} = {{p\left\lbrack {t - 1} \right\rbrack} - {\eta \frac{\partial C}{\partial p}}}},} & (13) \end{matrix}$

Referring to FIG. 4, at 401, the present system updates weights in W₁ ^(L) using gradients as in Equation (14) as follows:

$\begin{matrix} {{\frac{\partial C}{\partial w} = {{\frac{\partial L}{\partial w} + {\alpha \frac{\partial R_{n}}{\partial w}}} = {\frac{\partial L}{\partial w} + {\alpha \frac{2}{N}\left( {w - {Q_{n}\left( {w;\delta_{l}} \right)}} \right)1_{w \notin {B_{n}{(\delta_{l})}}}}}}},} & (14) \end{matrix}$

where B_(n)(δ_(l)) is the set of linear quantization cell boundaries, i.e., as in Equation (15) as follows:

$\begin{matrix} {{B_{n}\left( \delta_{l} \right)} = \left\{ {{\left( {\frac{{- 2^{n}} + 1}{2} + i} \right)\delta_{l}},{i = 0},1,\ldots \;,{2^{n} - 2}} \right\}} & (15) \end{matrix}$

The first term ∂L/∂w may be obtained from a back propagation method.

At 403, the present system updates weight quantization cell sizes δ_(l) ^(L) using gradients of Equation (16) as follows:

$\begin{matrix} {{\frac{\partial C}{\partial\delta_{l}} = {{\alpha \frac{\partial R_{n}}{\partial\delta_{l}}} = {{- \alpha}\frac{2}{N}{\Sigma_{w \in W_{l}}\left( {w - {Q_{n}\left( {w;\delta_{l}} \right)}} \right)}\frac{Q_{n}\left( {w;\delta_{l}} \right)}{\delta_{l}}1_{w \notin {B_{n}{(\delta_{l})}}}}}},\mspace{76mu} {{{where}\mspace{14mu} \frac{Q_{n}\left( {w;\delta_{l}} \right)}{\delta_{l}}} = {{{clip}\left( {{{round}\left( {w\text{/}\delta_{l}} \right)},\left\lbrack {{{- 2^{n}} - 1},{2^{n - 1} - 1}} \right\rbrack} \right)}.}}} & (16) \end{matrix}$

At 405, the present system updates the weight regularization coefficient α. Instead of directly updating α, the present system updates γ=log α using the gradient as in Equation (17) as follows:

$\begin{matrix} {\frac{\partial C}{\partial\gamma} = {{e^{\gamma}{R_{n}\left( {W_{1}^{L};\delta_{1}^{L}} \right)}} - {\lambda.}}} & (17) \end{matrix}$

At 407, the present system updates activation quantization cell sizes Δ₀ ^(L) using gradients of Equation (18) as follows:

$\begin{matrix} {{\frac{\partial C}{\partial\Delta_{l}} = {{\eta \frac{\partial S_{m}}{\partial\Delta_{l}}} = {{- \eta}\frac{2}{X_{l}}{\Sigma_{x \in X_{l}}\left( {w - {Q_{m}\left( {w;\Delta_{l}} \right)}} \right)}\frac{Q_{m}\left( {w;\Delta_{l}} \right)}{\Delta_{l}}\frac{Q_{m}\left( {x;\Delta_{l}} \right)}{\Delta_{l}}1_{x \notin {B_{m}{(\Delta_{l})}}}}}},\mspace{76mu} {{{where}\mspace{14mu} \frac{Q_{m}\left( {w;\Delta_{l}} \right)}{\Delta_{l}}} = {{{clip}\left( {{{round}\left( {x\text{/}\Delta_{l}} \right)},\left\lbrack {{- 2^{m - 1}},{2^{m - 1} - 1}} \right\rbrack} \right)}.}}} & (18) \end{matrix}$

At 409, if power-of-two quantization cell sizes are needed, additional gradients are included as in Equations (19) and (20) as follows:

$\begin{matrix} {{\frac{\partial C_{{pow}\; 2}}{\partial\delta_{l}} = {\frac{\partial C}{\partial\delta_{l}} + {\beta_{1}\frac{2}{L}\left( {\delta_{l} - {{round}_{{pow}\; 2}\left( \delta_{l} \right)}} \right)}}},} & (19) \\ {\frac{\partial C_{{pow}\; 2}}{\partial\Delta_{l}} = {\frac{\partial C}{\partial\Delta_{l}} + {\beta_{2}\frac{2}{L + 1}{\left( {\Delta_{l} - {{round}_{{pow}\; 2}\left( \Delta_{l} \right)}} \right).}}}} & (20) \end{matrix}$

During training, ω₁=log β₁ and ω₂=log β₂ are updated using gradients of Equations (21) and (22) as follows:

$\begin{matrix} {{\frac{\partial C_{{pow}\; 2}}{\partial\omega_{1}} = {{e^{\omega_{1}}{T\left( \delta_{1}^{L} \right)}} - \zeta_{1}}},} & (21) \\ {\frac{\partial C_{{pow}\; 2}}{\partial\omega_{2}} = {{e^{\omega_{2}}{T\left( \Delta_{0}^{L} \right)}} - {\zeta_{2}.}}} & (22) \end{matrix}$

At 411, if α>A for a sufficiently large and predetermined constant A or the number of iterations is greater than a predetermined number then training is terminated.

In order to enable backpropagation through quantization layers, the present system uses a straight-through estimator that passes the gradient from an upper layer to a lower layer, when the input is within the clipping boundary. Outside the clipping boundary, the gradient is determined to be zero. Stochastic rounding may be employed instead of deterministic rounding in quantization for better convergence.

Additional computation for gradients is not expensive, and the additional complexity only grows in O(N), where N is the number of weights. Thus, the method described above is applicable to deep neural networks with millions or tens of millions of parameters.

According to one embodiment, the method of weight quantization may be extended to include weight pruning. That is, for a threshold θ, a function for both weight quantization and weight pruning may be defined as in Equation (23) as follows:

$\begin{matrix} {{Q_{n}^{{Pruning} + {Quantization}}\left( {{x;\delta},\theta} \right)} = \left\{ \begin{matrix} 0 & {{,{{x} < \theta},}\mspace{34mu}} \\ {\delta \cdot {{clip}\left( {{{round}\left( {2\text{/}\delta} \right)},\left\lbrack {{- 2^{n - 1}},{2^{n - 1} - 1}} \right\rbrack} \right)}} & {,{{otherwise}.}} \end{matrix} \right.} & (23) \end{matrix}$

Equation (23) above outputs zero if the input is less than the threshold θ. Otherwise, Equation (23) outputs a quantized value of the input. Then, in order to achieve weight pruning in addition to weight quantization, the weight regularization in Equation (5) above is modified as in Equation (24) as follows:

$\begin{matrix} {{{R_{n}^{{Pruning} + {Quantization}}\left( {W_{1}^{L};\delta_{1}^{L}} \right)} = {\frac{1}{N}{\sum\limits_{l = 1}^{L}\; {\Sigma_{w \in W_{l}}{{w - {Q_{n}^{{Pruning} + {Quantization}}\left( {{w;\delta_{l}},\theta_{l}} \right)}}}^{2}}}}},} & (24) \end{matrix}$

where θ_(l) is either a pre-determined constant or a function of the weight values in each training iteration.

For example, for a target weight pruning rate r_(l) in each layer l, the threshold θ_(l) may be obtained from the r-th percentile of the absolute values for weights in each layer, which may be updated in each training iteration. The regularization then forces the weights below the threshold θ_(l) towards zero while other weights are quantized to their closest cell centers. The quantized low-precision weights may be further compressed in size by variable-rate coding, e.g., Huffman coding or arithmetic coding.

For example, for weight pruning, a pruning function may be as in Equation (25) as follows:

$\begin{matrix} {{P\left( {x;\theta} \right)} = \left\{ \begin{matrix} 0 & {{,{{x} < \theta},}\mspace{34mu}} \\ x & {,{{otherwise}.}} \end{matrix} \right.} & (25) \end{matrix}$

The weight pruning regularization term may be as in Equation (26) as follows:

$\begin{matrix} {{{R^{Pruning}\left( W_{1}^{L} \right)} = {\frac{1}{N}{\sum\limits_{l = 1}^{L}\; {\Sigma_{w \in W_{l}}{{w - {P\left( {w;\theta_{l}} \right)}}}^{2}}}}},} & (26) \end{matrix}$

where θ_(l) is either a pre-determined constant or a function of the weight values in each training iteration.

Similarly in Equation (24) above, for a target weight pruning rate r_(l) in each layer 1, the threshold θ_(l) may be obtained from the r-th percentile of the absolute values of weight in each layer, and the threshold θ_(l) may be updated in each training iteration. The regularization then causes the weights below the threshold θ_(l) to move towards zero.

According to one embodiment, the present system provides low-precision neural networks having quantized weights and feature maps. For example, quantized weights and feature maps are represented by fixed-point numbers of low-precision assuming that common scaling factors (i.e., fixed quantization cell sizes) are applied for weights and feature maps in each layer, respectively. Due to fixed-point weights and feature maps of low-precision, the present system lowers storage/memory requirements reduces computational costs; fixed-point arithmetic operations may be used instead of full-precision floating-point arithmetic operations.

Although certain embodiments of the present disclosure have been described in the detailed description of the present disclosure, the present disclosure may be modified in various forms without departing from the scope of the present disclosure. Thus, the scope of the present disclosure shall not be determined merely based on the described embodiments, but rather determined based on the accompanying claims and equivalents thereto. 

What is claimed is:
 1. A method, comprising: selecting a neural network model, wherein the neural network model includes a plurality of layers, and wherein each of the plurality of layers includes weights and activations; modifying the neural network model by inserting a plurality of quantization layers within the neural network model; associating a cost function with the modified neural network model, wherein the cost function includes a first coefficient corresponding to a first regularization term, and wherein an initial value of the first coefficient is pre-defined; and training the modified neural network model to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, further including optimizing a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, and wherein the quantized weights are quantized using the optimized weight scaling factor.
 2. The method of claim 1, further comprising optimizing the weight scaling factor and the activation scaling factor based on minimizing a minimum square quantization error (MSQE).
 3. The method of claim 1, further comprising inserting each quantization layer of the plurality of quantization layers after each activation output in each layer within the neural network model.
 4. The method of claim 1, wherein the cost function includes a second coefficient corresponding to a second regularization term based on the weight scaling factor and the activation scaling factor being power-of-two numbers.
 5. The method of claim 1, further comprising applying the quantized weights, the weight scaling factor, and the activation scaling factor to a fixed-point neural network, wherein the fixed-point neural network includes a plurality of convolutional layers, wherein each of the plurality of convolutional layers includes a convolution operation configured to receive feature maps and the quantized weights, a bias addition operation configured to receive an output of the convolution operation and biases, a first multiplying operation configured to receive an output of the bias addition operation and the first scale factor, an activation operation configured to receive an output of the first multiplier operation, a second multiplying operation configured to receive an output of the activation operation and the second scale factor, and a quantization operation configured to receive an output of the second multiplying operation.
 6. The method of claim 1, wherein training the neural network comprises: updating the weights by a stochastic gradient descent method; updating the weight scaling factor by the stochastic gradient descent method; updating the activation scaling factor by the stochastic gradient descent method; if the weight scaling factor and the activation scaling factor are of a power of two, including additional gradients of the stochastic descent method; updating the regularization coefficients by the stochastic gradient descent method; and terminating the training if either the regularization coefficient is greater than a pre-determined constant or a number of iterations of the method is greater than a predetermined limit.
 7. The method of claim 5, wherein the weights are fixed-point weights.
 8. The method of claim 5, wherein the first scale factor is a product of the weight scaling factor and the activation scaling factor.
 9. The method of claim 5, wherein the activation operation is a non-linear activation function.
 10. The method of claim 1, further comprising applying the quantized weights, the weight scaling factor, and the activation scaling factor to a fixed-point neural network, wherein the fixed-point neural network includes a plurality of convolutional layers, wherein each of the plurality of convolutional layers includes a convolution operation configured to receive feature maps and the quantized weights, a bias addition operation configured to receive an output of the convolution operation and biases, a rectified linear unit (ReLU) activation operation configured to receive an output of the bias addition operation, a scale-factor multiplying operation configured to receive an output of the ReLU activation operation and a scale factor, and a quantization operation configured to receive an output of the scale-factor multiplying operation.
 11. The method of claim 9, wherein the scale factor is a product of the weight scale factor and the quantization scale factor.
 12. An apparatus, comprising: a selector configured to select a neural network model, wherein the neural network model includes a plurality of layers, and wherein each of the plurality of layers includes weights and activations; an insertion device configured to modify the neural network model by inserting a plurality of quantization layers within the neural network model; an association device configured to associate a cost function with the modified neural network model, wherein the cost function includes a first coefficient corresponding to a first regularization term, and wherein an initial value of the first coefficient is pre-defined; and a training device configured to train the modified neural network model to generate quantized weights for a layer by increasing the first coefficient until all weights are quantized and the first coefficient satisfies a pre-defined threshold, and optimize a weight scaling factor for the quantized weights and an activation scaling factor for quantized activations, wherein the quantized weights are quantized using the optimized weight scaling factor.
 13. The apparatus of claim 12, further the training device is further configured to optimize the weight scaling factor and the activation scaling factor based on minimizing a minimum square quantization error (MSQE).
 14. The apparatus of claim 12, wherein the insertion device is further comprised to insert each quantization layer of the plurality of quantization layers after each activation output in each layer within the neural network model.
 15. The apparatus of claim 12, wherein the cost function includes a second coefficient corresponding to a second regularization term based on the weight scaling factor and the activation scaling factor being power-of-two numbers.
 16. The apparatus of claim 12, wherein the neural network is a fixed-point neural network to which the quantized weights, the weight scaling factor, and the activation scaling factor are applied, wherein the fixed-point neural network includes a plurality of convolutional layers, wherein each of the plurality of convolutional layers includes a convolution device configured to receive feature maps and the quantized weights, a bias addition device configured to receive an output of the convolution operation and biases, a first multiplier configured to receive an output of the bias addition device and the first scale factor, an activation device configured to receive an output of the first multiplier, a second multiplier configured to receive an output of the activation operation and the second scale factor, and a quantization operation configured to receive an output of the second multiplier.
 17. The apparatus of claim 12, wherein the training device is further comprised to: update the weights by a stochastic gradient descent method; update the weight scaling factor by the stochastic gradient descent method; update the activation scaling factor by the stochastic gradient descent method; if the weight scaling factor and the activation scaling factor are of a power of two, include additional gradients of the stochastic descent method; update the regularization coefficients by the stochastic gradient descent method; and terminate the training if either the regularization coefficient is greater than a pre-determined constant or a number of iterations is greater than a predetermined limit.
 18. The apparatus of claim 16, wherein the weights are fixed-point weights.
 19. The apparatus of claim 16, wherein the first scale factor is a product of the weight scaling factor and the activation scaling factor.
 20. The apparatus of claim 16, wherein the activation device is a non-linear activation device.
 21. The apparatus of claim 12, wherein the neural network is a fixed-point neural network to which is applied the quantized weights, the weight scaling factor, and the activation scaling factor, wherein the fixed-point neural network includes a plurality of convolutional devices, wherein each of the plurality of convolutional devices is configured to receive feature maps and the quantized weights, a bias addition device configured to receive an output of the convolution device and biases, a rectified linear unit (ReLU) activation device configured to receive an output of the bias addition device, a scale-factor multiplier configured to receive an output of the ReLU activation device and a scale factor, and a quantization device configured to receive an output of the scale-factor multiplier.
 22. The apparatus of claim 20, wherein the scale factor is a product of the weight scale factor and the quantization scale factor. 